﻿@using PagedList
@using PagedList.Mvc
@using CodeCamp.Models.Logs
@model LogSearchViewModel
@{
    var grid = new WebGrid(Model.SearchResults, canPage: false, canSort: false);
}

@if ((Model.SearchResults != null) && (Model.SearchResults.Count > 0))
{
    <div id="logPager1">
    @Html.PagedListPager(Model.SearchResults,
        page => Url.Action("List", new RouteValueDictionary()
        {
            { "Page", page }
        }),
        PagedListRenderOptions.OnlyShowFivePagesAtATime)
    </div>

        @grid.GetHtml(
        tableStyle: "grid-table",
        headerStyle: "grid-head",
        alternatingRowStyle: "grid-alt-row",
        columns: grid.Columns(
            grid.Column(columnName: "",
                header: "",
                format: @<text>@Html.ActionLink("Detail", "Detail", new { id = @item.LogEntryID }, new { target = "_blank" })</text>
            ),
            grid.Column("EntryTime",
                "Entry Time (local)",
                style: "ui-nowrap",
                format: @<text>@string.Format("{0:dd-MMM  hh:mm:ss tt}", item.LogTimeLocal)</text>
            ),
            grid.Column("Level"),
            grid.Column("MachineName", "Machine", canSort: false),
            grid.Column("ThreadId", "Thread Id"),
            grid.Column("RemoteIPNoNull", "Remote IP", style: "ui-nowrap"),
            grid.Column("UserNameNoNull", "Username"),
            grid.Column("SimplifiedUrl", "URL"),
            grid.Column("MessageHeadline", "Message")
        )
    )

    <hr />
    <div id="logPager2">
    @Html.PagedListPager(Model.SearchResults,
        page => Url.Action("List", new RouteValueDictionary()
        {
            { "Page", page }
        }),
        PagedListRenderOptions.OnlyShowFivePagesAtATime)
    </div>
}

@using (Html.BeginForm("List", "Logs", FormMethod.Post))
{
    @Html.ValidationSummary(false)
    @Html.HiddenFor(model => model.FilterTimeTicks)
    <fieldset>
        <legend>Log Entry Search</legend>

        <table>
            <tr>
                <td class="editor-label">(@Html.EditorFor(x => x.RemoteIPNotEq) not) @Html.LabelFor(x => x.RemoteIP): </td>
                <td class="editor-field">@Html.EditorFor(x => x.RemoteIP) @Html.EditorFor(x => x.RemoteIPExcludeNull)&nbsp;Exclude&nbsp;Null</td>
                <td rowspan="3" valign="bottom">
                    <input name="SearchButton" type="submit" value="Search" /><br />
                    <input name="ClearButton" type="submit" value="Clear" />
                </td>
            </tr>
            <tr>
                <td class="editor-label">(@Html.EditorFor(x => x.UserNameNotEq) not) @Html.LabelFor(x => x.UserName): </td>
                <td class="editor-field">@Html.EditorFor(x => x.UserName) @Html.EditorFor(x => x.UserNameExcludeNull)&nbsp;Exclude&nbsp;Null</td>
            </tr>
            <tr>
                <td class="editor-label">(@Html.EditorFor(x => x.LogLevelsNot) not) Log Level(s): </td>
                <td class="editor-field">
                @foreach (var ll in Model.LogLevels)
                { 
                    @*@Html.Partial("EditorTemplate/LogLevelViewModel", ll) *@
                    if (ll.IsChecked)
                    {
                        <input type="checkbox" checked="checked" value="@ll.LogLevelName" name="logLevel" /><text>&nbsp;@ll.LogLevelName</text>
                    }
                    else
                    {
                        <input type="checkbox" value="@ll.LogLevelName" name="logLevel" /><text>&nbsp;@ll.LogLevelName</text>
                    }
                }
                @* @Html.EditorFor(x => x.LogLevels, "LogLevelViewModel") *@
                </td>
            </tr>
        </table>
    </fieldset>

    @Html.HiddenFor(model => model.UTCOffsetMinutes)

<script language="javascript">
    ourDate = new Date
    var uom = document.getElementById("UTCOffsetMinutes");
    if (uom != null) {
        uom.value = ourDate.getTimezoneOffset();
    }
</script>    
}
